package com.itsci.assignment2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class EditTravel extends Activity{
	private EditText name;
	private EditText price;
	private EditText des;
	private Button save;
	private TravelManager traMgr;
	private String intentName;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.edit_travel);
		name = (EditText)findViewById(R.id.editText_editTravel_name);
		price = (EditText)findViewById(R.id.editText_editTravel_price);
		des = (EditText)findViewById(R.id.editText_editTravel_description);
		Intent intent = getIntent();
		intentName = intent.getStringExtra("name");
		name.setText(intent.getStringExtra("name"));
		price.setText(intent.getStringExtra("price"));
		des.setText(intent.getStringExtra("des"));
		save = (Button)findViewById(R.id.button_editTravel_save);
		traMgr = new TravelManager(EditTravel.this, null, null, 1);
		
		save.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				TravleBean tr = new TravleBean(traMgr.getId(intentName),name.getText().toString(),Integer.parseInt(price.getText().toString()),des.getText().toString());

				traMgr.updateTravel(tr);
				Intent gotoEdit = new Intent(EditTravel.this,ShowVehicle.class);
				gotoEdit.putExtra("name",name.getText().toString());
				gotoEdit.putExtra("price",price.getText().toString());
				gotoEdit.putExtra("des",des.getText().toString());
				setResult(111,gotoEdit);
				finish();
				
			}
		});
		
		
	}
}
